﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KSOAPlus
{
    public partial class billquery : Form
    {
        public billquery()
        {
            InitializeComponent();
        }

        Common Init = new Common();
        MsSqlHelper mssql = new MsSqlHelper();

        private void btnQuery_Click(object sender, EventArgs e)
        {
            string srq = dTPStart.Text;
            string erq = dTPEnd.Text;
            string code = txtCode.Text;
            string ywy = txtywy.Text;
            string company = txtCompany.Text;
            string sql = "select a.djbh,a.isdz,a.dzlx,a.rq,b.danwbh,b.dwmch,b.lxr,a.lastdate,a.end_rq,a.shqye, a.bqysye,a.bqyfye,a.bqdzje,a.bqdfqrje,"
                    +"a.bqcyje,a.beizhu,b.ywy, a.is_zx,"
                    +"case when a.isdz='否' then isnull(a.ywshenhe,'否') else '是' end as ywshenhe, a.is_qr,"
                    +"a.yinjlx,a.username "
                    +" from wldzdjhz a(nolock)"
                    +" join mchk b(nolock) on a.dwbh=b.dwbh "
                    + " where a.is_zx<>'清' and a.rq between '" + srq + "' and '" + erq + "' and b.danwbh like '" + code + "%' and b.dwmch like '%" + company + "%' and b.ywy like '" + ywy + "%'"
                    +" group by a.dzlx,a.rq,a.djbh,b.danwbh,b.dwmch,b.lxr,a.lastdate,a.end_rq,a.shqye, a.bqysye,a.bqyfye,a.bqdzje,a.bqdfqrje,a.bqcyje,a.beizhu,b.ywy,"
                    +" a.is_zx,a.ywshenhe,a.is_qr,a.yinjlx,a.username,a.isdz ";
            DataTable dt = mssql.ExecuteDt(sql);
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                string ColumnName = mssql.GetString("select top 1 rtrim(chnname) chnname  from fldlist where fdname=rtrim('" + dt.Columns[i].ToString() + "')");
                if (!dt.Columns.Contains(ColumnName))
                {
                    dt.Columns[i].ColumnName = ColumnName;
                }
            }
            dGV.DataSource = dt;
        }

        private void dGV_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int row = this.dGV.CurrentCell.RowIndex;//选定当前选定的单元格所处的行号
            int col = this.dGV.CurrentCell.ColumnIndex;//选定当前选定的单元格所处的列号
            string id = dGV.Rows[row].Cells[0].Value.ToString();//将单元格的内容显示到文本
            //MessageBox.Show(id);
            DZHToExcel DZHToExcel = new DZHToExcel();
            DZHToExcel.DZDID = id;
            DZHToExcel.ShowInTaskbar = false;
            DZHToExcel.ShowDialog();
            
        }
    }
}
